
package com.yiqi.news.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;

import com.jess.arms.utils.LogUtils;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.yiqi.news.BuildConfig;
import com.yiqi.news.app.EventBusTags;

import org.simple.eventbus.EventBus;


public class RealWXEntryActivity extends Activity implements IWXAPIEventHandler {

    private IWXAPI mWxApi = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LogUtils.warnInfo("=====>" + ((getIntent() == null || getIntent().getExtras() == null) ? "" : getIntent().getExtras().toString()));

        EventBus.getDefault().post(new Login3rdEvent(1999, -1, getIntent()), EventBusTags.LOGIN_3_RDEVENT);

        mWxApi = WXAPIFactory.createWXAPI(this, BuildConfig.APP_ID_WECHAT, false);
        mWxApi.registerApp(BuildConfig.APP_ID_WECHAT);
        mWxApi.handleIntent(getIntent(), this);

        finish();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        LogUtils.warnInfo("=====>" + ((getIntent() == null || getIntent().getExtras() == null) ? "" : getIntent().getExtras().toString()));

        setIntent(intent);
        EventBus.getDefault().post(new Login3rdEvent(1999, -1, intent), EventBusTags.LOGIN_3_RDEVENT);

        mWxApi.handleIntent(intent, this);

        finish();
    }


    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                EventBus.getDefault().post(new Message(), EventBusTags.SHARE_OK);
                break;
        }
    }
}